package cn.weiwei.WHadoop.hdfs.filesystem;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;

/**
 * @author WangWeiwei
 * @version 1.0
 * @sine 17-2-12
 * 显示hadoop文件系统中一组路径的文件信息
 */
public class ListStatus {
    public void listStatus(String[] args) throws IOException {
        String uri = args[0];
        Configuration configuration = new Configuration();
        FileSystem fileSystem = FileSystem.get(URI.create(uri),configuration);

        Path[] paths = new Path[args.length];
        for (int i = 0;i < paths.length; i++){
            paths[i] = new Path(args[i]);
        }
        FileStatus[] fileStatuses = fileSystem.listStatus(paths);
        Path[] listedPaths = FileUtil.stat2Paths(fileStatuses);
        for (Path path : listedPaths){
            System.out.println(path);
        }
    }
}
